package com.lagou.server;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerInitClose {

    private ServerSocket ss;
    private Socket s;
    private ObjectInputStream ois;
    private ObjectOutputStream oos;

    public ObjectInputStream getOis() {
        return ois;
    }

    public void setOis(ObjectInputStream ois) {
        this.ois = ois;
    }

    public ObjectOutputStream getOos() {
        return oos;
    }

    public void setOos(ObjectOutputStream oos) {
        this.oos = oos;
    }

    /**
     * 自定义成员方法实现服务端的初始化
     * @throws IOException
     */
    public void ServerInit() throws IOException {

        //创建ServerSocket
        ss = new ServerSocket(8888);
        System.out.println("等待客户端请求...");

        //等待客户端连接请求
        s = ss.accept();

        //使用输入输出流进行通信
        ois = new ObjectInputStream(s.getInputStream());
        oos = new ObjectOutputStream(s.getOutputStream());
        System.out.println("服务器初始化成功！");

    }


    /**
     * 自定义成员方法实现服务端的关闭
     * @throws IOException
     */
    public void ServerClose() throws IOException {
        oos.close();
        ois.close();
        s.close();
        ss.close();
    }


}
